|
|
@@ -10,7 +10,7 @@ module Agents
|
10
|
10
|
|
11
|
11
|
To be able to use the Aftership API, you need to generate an `API Key`. You need a paying plan to use their tracking feature.
|
12
|
12
|
|
13
|
|
- You can use this agent to either retrieve or delete data. The keys are `get` and `delete`. You have to provide a specific request and its associated option.
|
|
13
|
+ You can use this agent to retrieve tracking data. You have to provide a specific `get` request and its associated option.
|
14
|
14
|
|
15
|
15
|
To get all trackings for your packages please enter `get` for key and `/trackings` for the option.
|
16
|
16
|
To get tracking for a specific tracking number, add the extra options `slug`, `tracking_number` and set `single_tracking_request` to true.
|
|
|
@@ -20,13 +20,8 @@ module Agents
|
20
|
20
|
To get the last checkpoint of a package set key to `get` and option to `/last_checkpoint` plus provide `slug` and `tracking_number`
|
21
|
21
|
|
22
|
22
|
`slug` is a unique courier code.
|
23
|
|
-
|
24
|
|
- You have two options to get courier information along with `get`, `/couriers`
|
25
|
|
- which returns the couriers that are activiated at your account and the other is `/couriers/all` which returns all couriers.
|
26
|
23
|
|
27
|
|
- The `delete` option allows you to delete a specific shipment. It is `/trackings/:slug/:tracking_number`.
|
28
|
|
-
|
29
|
|
- All urls must be properly formatted with a `/` in front.
|
|
24
|
+ You can get a list of courier information here `https://www.aftership.com/courier`
|
30
|
25
|
|
31
|
26
|
Required Options:
|
32
|
27
|
|
|
|
@@ -122,14 +117,8 @@ module Agents
|
122
|
117
|
interpolated[:single_tracking_request] != "false"
|
123
|
118
|
end
|
124
|
119
|
|
125
|
|
- def uri
|
126
|
|
- uri = URI.parse API_URL
|
127
|
|
- if single_tracking_request?
|
128
|
|
- uri.query = interpolated['get']+ '/' + interpolated['slug'] + '/' + interpolated['tracking_number'] if uri.query.nil?
|
129
|
|
- else
|
130
|
|
- uri.query = interpolated['get'] if uri.query.nil?
|
131
|
|
- end
|
132
|
|
- uri.to_s.gsub('?','')
|
|
120
|
+ def last_checkpoint?
|
|
121
|
+ interpolated[:last_checkpoint_request] != "false"
|
133
|
122
|
end
|
134
|
123
|
|
135
|
124
|
def working?
|
|
|
@@ -141,14 +130,31 @@ module Agents
|
141
|
130
|
errors.add(:base, "Content-Type must be set to application/json") unless options['Content_Type'].present? && options['Content_Type'] == 'application/json'
|
142
|
131
|
end
|
143
|
132
|
|
144
|
|
- def request_options
|
145
|
|
- {:headers => {"aftership-api-key" => interpolated['api_key'], "Content-Type"=>"application/json"} }
|
146
|
|
- end
|
147
|
|
-
|
148
|
133
|
def check
|
149
|
|
- response = HTTParty.get(uri, request_options)
|
|
134
|
+ if single_tracking_request? || last_checkpoint?
|
|
135
|
+ response = HTTParty.get(single_or_checkpoint_tracking_url, request_options)
|
|
136
|
+ else
|
|
137
|
+ response = HTTParty.get(trackings_url, request_options)
|
|
138
|
+ end
|
150
|
139
|
events = JSON.parse response.body
|
151
|
140
|
create_event :payload => events
|
152
|
141
|
end
|
|
142
|
+
|
|
143
|
+ private
|
|
144
|
+ def base_url
|
|
145
|
+ "https://api.aftership.com/v4/"
|
|
146
|
+ end
|
|
147
|
+
|
|
148
|
+ def trackings_url
|
|
149
|
+ base_url + "#{URI.encode(interpolated[:get].to_s)}"
|
|
150
|
+ end
|
|
151
|
+
|
|
152
|
+ def single_or_checkpoint_tracking_url
|
|
153
|
+ base_url + "#{URI.encode(interpolated[:get].to_s)}/#{URI.encode(interpolated[:slug].to_s)}/#{URI.encode(interpolated[:tracking_number].to_s)}"
|
|
154
|
+ end
|
|
155
|
+
|
|
156
|
+ def request_options
|
|
157
|
+ {:headers => {"aftership-api-key" => interpolated['api_key'], "Content-Type"=>"application/json"} }
|
|
158
|
+ end
|
153
|
159
|
end
|
154
|
160
|
end
|